<?php
	require_once("user_session.php");

	# $_GET parameters:
#   1. eventType:    approve/disapprove/deny
#   2. elementType:  d/p/t
#   3. id

	

	if(!isset($_SESSION["userType"])
   		|| $_SESSION["userType"] == "0")
	{
	   	echo "<script language=javascript>window.history.back();</script>";
	}else{
		switch($_GET["elementType"])
		{
			case "d":
				$r = EKDocument::administrate($_GET["id"], $_GET["eventType"]);
				break;
			case "p":
				$r = EKParagraph::administrate($_GET["id"], $_GET["eventType"]);
				break;
			case "t":
				$r = EKTalk::administrate($_GET["id"], $_GET["eventType"]);
				break;
			default:
				$r = "Unsupportted parameter!";
		}
		
		echo "<script language=javascript>\n";
			
		if($_GET["eventType"]!="deny")
		{
			# it is the approve or disapprove or unsupported action
			echo "alert(\"".$r."\");\n".
				"history.go(-1);\n";
		}else{
			if(substr($r,0,1)=="_") // Judge whether it is an id
			{
				# it is a success deny action
				echo "alert(\"Denying performed!\");\n".
					"self.location=\"document.php?id=".$r."&method=v\";\n";
			}else{
				# it is a failed deny action
				echo "alert(\"".$r."\");\n".
					"history.go(-1);\n";
			}
		}
		
		echo "</script>";
	}
?>